package Basic;

import java.io.File;

public class Multithreading {
	public static class PhotoHandle {
/*        public static void main(String[] args) {
            File file = new File("D:\\photo.bmp");
            photoHandle(file, 4);//把文件分成4个线程来处理
        }*/
        public static void photoHandle(File file, int threadNumber) {
            long length = file.length();
            long unitLength = length/threadNumber;//把图片长度按线程数等分
            for(int i=0; i<threadNumber; i++){
                long begin = 54;//图片一开始都不从零开始的
                long end = length;
                if (i != 0){
                    begin = unitLength*i;
                }
                if(i!=threadNumber-1){
                    end = unitLength*(i+1)-1;
                }
                String name = "线程"+i;
                MyThread myThreads = new MyThread(name, file, begin, end);
                new Thread(myThreads).start();
                System.out.println(name + "已开启");
            }
        }
    }

}
